//
//  MineController.m
//  基本框架
//
//  Created by runone02 on 2018/6/26.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "MineController.h"

#import "LQYTopCell.h"
#import "LQbottomCell.h"
#import "LQYMineTableViewCell.h"
#import "LQYFriendCircleController.h"
#import "SetupViewController.h"
#import "MyDetailsConteroller.h"
@interface MineController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * MineTableView;
@property (nonatomic, strong) LQYTopCell *topcell;
@property (nonatomic, strong) LQbottomCell *bottomCell;
@property (nonatomic, strong) LQYMineTableViewCell *mineTableCell;
@property (nonatomic, strong) NSArray *dataArr;
@end

@implementation MineController

static NSString *topCellID = @"LQYTopCell";
static NSString *bottomCellID = @"LQbottomCell";
static NSString *mineTableCellID = @"LQYMineTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavView];
    [self loadTopView];
}


- (void) setupNavView{
    [super setupNavView];
    self.navView.backgroundColor = [UIColor whiteColor];
}

- (void)loadTopView{
    
    self.MineTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.MineTableView.delegate = self;
    self.MineTableView.dataSource = self;
    self.MineTableView.bounces = YES;

    self.MineTableView.separatorInset = UIEdgeInsetsZero;
    [self.MineTableView registerClass:[LQYTopCell class] forCellReuseIdentifier:topCellID];
     [self.MineTableView registerClass:[LQYMineTableViewCell class] forCellReuseIdentifier:mineTableCellID];
    
    [self.view addSubview:self.MineTableView];
    [self.MineTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(self.view);
    }];
    self.bottomCell = [[LQbottomCell alloc]init];
    self.bottomCell.backgroundColor = RGB(238, 238, 238);
    [self.MineTableView setTableFooterView:self.bottomCell];
    self.MineTableView.sectionFooterHeight = 0;
    
    self.dataArr = @[@[@{nameLabel: @"11" , firmNameLabel:@"gongs", authenticationBtn:@"123456789", icon : @"MoreMyBankCard", medalBtn : @"shenm", stateBtn : @"zhuant"}],
                     
                     @[
                         @{FindCellImageName:@"MoreMyBankCard", FindCellContentStr:@"指数"},
                         @{FindCellImageName:@"MoreMyBankCard", FindCellContentStr:@"学习中心"},
                         @{FindCellImageName:@"MoreMyBankCard", FindCellContentStr:@"福利"},
                         @{FindCellImageName:@"MoreExpressionShops", FindCellContentStr:@"表情"}
                         ],
                     
                     @[
                         @{FindCellImageName:@"MoreMyFavorites", FindCellContentStr:@"收藏"},
                         @{FindCellImageName:@"ff_IconShowAlbum", FindCellContentStr:@"相册"},
                         @{FindCellImageName:@"MyCardPackageIcon", FindCellContentStr:@"卡包"},
                         
                         ],
                     
                     @[
                         @{FindCellImageName:@"MoreSetting", FindCellContentStr:@"设置"}]
                     ];
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 160;
    } else {
        return 45;
    }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.dataArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        self.topcell = [tableView dequeueReusableCellWithIdentifier:topCellID forIndexPath:indexPath];
        [self.topcell setContentData:[self.dataArr[indexPath.section] objectAtIndex:indexPath.row]];
        [self addTapGesture];
        return self.topcell;
    } else {
        self.mineTableCell = [tableView dequeueReusableCellWithIdentifier:mineTableCellID forIndexPath:indexPath];
        [self.mineTableCell setContentData:[self.dataArr[indexPath.section] objectAtIndex:indexPath.row]];
        return self.mineTableCell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            LQYFriendCircleController * friend = [[LQYFriendCircleController alloc]init];
            [self.navigationController pushViewController:friend animated:YES];
        }else if (indexPath.row == 1){
             NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }else if (indexPath.row == 2){
             NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }else{
             NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }
    }else if (indexPath.section == 2){
        if (indexPath.row == 0) {
             NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }else if (indexPath.row == 1){
             NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }else{
            NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        }
    }else{
         NSLog(@"第%ld组,第%ld行",(long)indexPath.section,(long)indexPath.row);
        SetupViewController * setUpView = [[SetupViewController alloc]init];
        [self.navigationController pushViewController:setUpView  animated:YES];
    }
    
}


//添加点击
- (void) addTapGesture{
    //名字
    UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nameLabelClick)];
    [self.topcell.nameLabel addGestureRecognizer:labelTapGestureRecognizer];
    self.topcell.nameLabel.userInteractionEnabled = YES;
    //二维码
    [self.topcell.QRCodeBtn addTarget:self action:@selector(QRCodeBtnClack:) forControlEvents:UIControlEventTouchUpInside];
    //头像
    [self.topcell.icon addTarget:self action:@selector(nameLabelClick) forControlEvents:UIControlEventTouchUpInside];
    //公司名
    UITapGestureRecognizer *firmNameLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(firmNameLabelClack)];
    [self.topcell.firmNameLabel addGestureRecognizer:firmNameLabel];
    self.topcell.firmNameLabel.userInteractionEnabled = YES;
    
    //认证
    [self.topcell.authenticationBtn addTarget:self action:@selector(authenticationBtnClack:) forControlEvents:UIControlEventTouchUpInside];
    
    //勋章
    [self.topcell.medalBtn addTarget:self action:@selector(medalBtnClack:) forControlEvents:UIControlEventTouchUpInside];
    
    //状态
    [self.topcell.stateBtn addTarget:self action:@selector(stateBtnClack:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark  点击名字
- (void) nameLabelClick{
    MyDetailsConteroller * friend = [[MyDetailsConteroller alloc]init];
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:friend animated:YES];
}

#pragma mark 公司名字点击
- (void) firmNameLabelClack{
    NSLog(@"公司名字点击");
}
#pragma mark  二维码点击
- (void)QRCodeBtnClack:(UIButton *)sender {
    NSLog(@"二维码点击");
}

#pragma mark 认证
- (void)authenticationBtnClack:(UIButton *)sender {
    NSLog(@"认证点击");
}

#pragma mark 勋章
- (void)medalBtnClack:(UIButton *)sender {
    NSLog(@"勋章点击");
}

#pragma mark 状态
- (void)stateBtnClack:(UIButton *)sender {
 
}


@end
